home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 18077 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  4.9 KB

  1. Path: mics.demon.co.uk!Bill
  2. From: Bill Michell <Bill@mics.demon.co.uk>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: MFC Appl. only containing a dialog
  5. Date: Wed, 17 Apr 1996 13:29:36 +0100
  6. Organization: None
  7. Distribution: world
  8. Message-ID: <w+4ArLAwQOdxEwwP@mics.demon.co.uk>
  9. References: <TBD2JR_3.96Apr11101925@pruef1.atlas.de> <316DC9D3.7FCD@panix.com>
  10. NNTP-Posting-Host: mics.demon.co.uk
  11. X-NNTP-Posting-Host: mics.demon.co.uk
  12. MIME-Version: 1.0
  13. X-Newsreader: Turnpike Version 1.12 <uiEOes1orVXTvvWgSAnAOBUy+p>
  14.  
  15. In article <316DC9D3.7FCD@panix.com>, Alex Chacha <achacha@panix.com>
  16. writes
  17. >cae2/test/pruef1 Joerg Redenius wrote:
  18. >
  19. >> I want to write a very simple application using my MSVC++ 1.52.
  20. >> The application should only display a small dialog WITH help
  21. >> feature.
  22. >
  23. >This is relatively easy:
  24. >1. create an application using appwizard
  25. >2. using appstudio create a dialog you want to use
  26. >3. using classwizard create the class for your new dialog
  27. >4. remove the doc template in winapp and it's usage (mostly in
  28. >InitInstance)
  29. >5. remove view/doc/frame files from your project
  30. >6. delete them (so they don't clutter your sub-dir)
  31. >7. in InitInstance find the routine (m_pMainWnd = ...)
  32. >8. replace it with:
  33. >  CMyDialog *dialogX = new CMyDialog;
  34. >  m_pMainWnd = dialogX;
  35. >
  36. >(Don't remember if you need to call DoModal, but I think you do)
  37. >
  38. >9. for non modal dialogs you have to call CMyDialog::Create function,
  39. >but this is rare...
  40. >
  41. >Let me know how it went.  I did this on several occasions with much
  42. >success...
  43. >
  44. There are a few extra things you will need to do if you want the dialog
  45. box to have a properly working minimise button. I got the code from a
  46. nic man from microsoft:
  47. From stephsm@microsoft.com Wed Jan 10 17:20:14 1996
  48.  
  49. Below is the code snippet I mentioned. You need to provide 
  50. functionality for the following three functions, as well as adding the 
  51. m_hIcon member variable for
  52. your dialog class.
  53. The OnPaint function handles the drawing of the icon.
  54. The OnQueryDragIcon function handles the dragging of the icon around the
  55. screen
  56. by the user.
  57. The Constructor loads the icon, and passes the icon's handle into the
  58. m_hIcon
  59. member variable. Remember to provide an icon resource to pass to
  60. LoadIcon!
  61.  
  62.  
  63. If you have any more problems, don't hesitate to give us a call!
  64.  
  65. Regards,
  66.  
  67. Steve Smith, Microsoft Systems Developer Support.
  68.  
  69.  
  70. // If you add a minimize button to your dialog, you will need the code
  71. below
  72. //  to draw the icon.  For MFC applications using the document/view
  73. model,
  74. //  this is automatically done for you by the framework.
  75.  
  76. void CDemoDlg::OnPaint()
  77. {
  78.         if (IsIconic()) // This member function returns TRUE if a window
  79.                         // is iconised. Otherwise (suprisingly) it
  80. returns FALSE.
  81.         {
  82.                 CPaintDC dc(this); // device context for painting
  83.  
  84.                 SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(),
  85. 0);
  86.                 // This message ensures the background behind where the
  87.                 // Icon is to be drawn is painted with the brush of the
  88. parent
  89.                 // window - or repaint the desktop in that area.
  90.  
  91.                 // Center icon in client rectangle
  92.                 int cxIcon = GetSystemMetrics(SM_CXICON);
  93.                 int cyIcon = GetSystemMetrics(SM_CYICON);
  94.                 // The GetSystemMetrics function returns system
  95. information,
  96.                 // such as screen size (in pixels) and loads of other
  97. stuff.
  98.                 // This can be a useful function - have a look at the
  99. documentation
  100.                 // for it in the online help.
  101.  
  102.                 CRect rect;
  103.                 GetClientRect(&rect);
  104.                 int x = (rect.Width() - cxIcon + 1) / 2;
  105.                 int y = (rect.Height() - cyIcon + 1) / 2;
  106.  
  107.                 // Draw the icon
  108.                 dc.DrawIcon(x, y, m_hIcon);
  109.                 // Draw icon onto display context.
  110.         }
  111.         else
  112.         {
  113.                 CDialog::OnPaint();
  114.                 // If you had your own OnPaint code for the dialog, you
  115. would
  116.                 // place that here.
  117.         }
  118. }
  119.  
  120. // The system calls this to obtain the cursor to display while the user
  121. drags
  122. //  the minimized window. this is necessary if you want the user to be 
  123. able to drag the
  124. // icon around the screen!
  125. HCURSOR CDemoDlg::OnQueryDragIcon()
  126. {
  127.         return (HCURSOR) m_hIcon;
  128.         // Tells windows to use the icon as a cursor while the user is
  129. dragging.
  130. }
  131.  
  132. CDemoDlg::CDemoDlg(CWnd* pParent /*=NULL*/)
  133.         : CDialog(CDemoDlg::IDD, pParent)
  134. {
  135.         //{{AFX_DATA_INIT(CDemoDlg)
  136.                 // NOTE: the ClassWizard will add member initialization
  137. here
  138.         //}}AFX_DATA_INIT
  139.         // Note that LoadIcon does not require a subsequent DestroyIcon
  140. in Win32
  141.         // But you will probably (!) need it for win16 - you would place
  142. the destroy
  143.         // icon in the CDemoDlg::~CDemoDlg function.
  144.  
  145.         m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  146. }
  147.  
  148.  
  149.  
  150. -- 
  151. Bill Michell   eMail: Bill@mics.demon.co.uk
  152.